package com.socket;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;

public class StreamTool {

	public static byte[] readStream(InputStream input) throws Exception {
//		ByteArrayOutputStream output=new ByteArrayOutputStream();
//		byte[] buff=new byte[1024];
//		int len=-1;
//		while((len=input.read(buff))!=-1){
//			output.write(buff,0,len);
//		}
//		output.close();
//		input.close();
//		return output.toByteArray();
		int count=0;
		while(count==0){
			count=input.available();
		}
		byte[] bt=new byte[count];
		input.read(bt);
		return bt;
	}
	
	public static void main(String[] args) throws Exception{
		File file=new File("D:\\eclipse-jee-juno-SR1-win32\\workplace\\JavaSrc\\src\\com\\io\\input\\file.txt");
		try {
			FileInputStream input = new FileInputStream(file);
			byte[] filebt=readStream(input);
			System.out.println(filebt.length);
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	
}
